package org.eden.heartbeat.core.ping;

import org.eden.heartbeat.api.model.MachineInfo;
import org.eden.heartbeat.core.ping.impl.NullPingServiceImpl;
import org.eden.heartbeat.core.ping.impl.SocketPingServiceImpl;

/**
 * Object factory for ping services.
 *
 * @author trsimoes
 * @version $Revision:$
 */
public class PingServiceFactory {

    private static PingServiceFactory ourInstance = new PingServiceFactory();

    public static PingServiceFactory getInstance() {
        return ourInstance;
    }

    private PingServiceFactory() {
    }

    /**
     * Creates a new ping service for the {@code machineInfo}.
     *
     * @param machineInfo information needed to ping a machine.
     * @return new instance of {@code PingService}.
     */
    public PingService createNew(MachineInfo machineInfo) {

        if (machineInfo == null) {
            return new NullPingServiceImpl();
        }

        return new SocketPingServiceImpl(machineInfo);
    }
}
